/*
 ----------------------------------------------------------------------------------
                          "THE BEER-WARE COPYRIGHT LICENSE"
                                    (Revision 43)
                                     -----------
   Rymek [rymek@rymek.org] wrote this file. As long as You retain this notice and
   this file has been sent directly to You by the author, You can do whatever You
   want with this stuff as long as You don't sell or rent it. If we meet some day,
   and You think this stuff is worth it, You can buy me a beer in return :-)
                                                                __________
                                                                Paweł Rymaszewski
 ----------------------------------------------------------------------------------
 */

package processing.objects;

import processing.logic.util.Mapper;

/**
 * Represents Message object containing
 * additional message info
 *
 * @author rymek
 *         User: rymek
 *         Date: 30.06.11
 *         Time: 10:10
 */
public class Message {

    private String requestName = "";     // Message Request name
    private String responseName = "";    // Message Response name (only SYNC messages)
    private String serviceName = "";     // WM Service / PS Method name
    private String channelName = "";     // Communication channel requestName
    private String nodeName = "";        // Message Node name
    private String transactionType = ""; // Message transaction type - IA, OA, IS, OS
    private String effectiveDate = "";   // Date since when the message is available
    private boolean active;              // Determines if message is active
    private int messageType;             // Message type (SYNC/ASYNC)
    private int serverNbr;               // ID of the target server (only for custom publisher messages)
    private boolean customPublisher;     // Determines if message is custom publisher message

    /**
     * Default constructor
     */
    public Message() {
    }

    /**
     * Copy constructor.
     *
     * @param message input message
     */
    public Message(Message message) {
        this.requestName = message.getRequestName();
        this.responseName = message.getResponseName();
        this.serviceName = message.getServiceName();
        this.channelName = message.getChannelName();
        this.nodeName = message.getNodeName();
        this.transactionType = message.getTransactionType();
        this.effectiveDate = message.getEffectiveDate();
        this.active = message.isActive();
        this.messageType = message.getMessageType();
        this.serverNbr = message.getServerNbr();
        this.customPublisher = message.isCustomPublisher();
    }

    public String getRequestName() {
        return requestName;
    }

    public void setRequestName(String requestName) {
        this.requestName = requestName;
    }

    public int getMessageType() {
        return messageType;
    }

    void setMessageType(int messageType) {
        this.messageType = messageType;
    }

    public String getServiceName() {
        return serviceName;
    }

    public void setServiceName(String serviceName) {
        this.serviceName = serviceName;
    }

    public String getChannelName() {
        return channelName;
    }

    public String getNodeName() {
        return nodeName;
    }

    public void setNodeName(String nodeName) {
        this.nodeName = nodeName;
    }

    public void setChannelName(String channelName) {
        this.channelName = channelName;
    }

    public String getTransactionType() {
        return transactionType;
    }

    public void setTransactionType(String transactionType) {
        this.transactionType = transactionType;
        this.setMessageType(Mapper.mapMessageTypeFromTransaction(transactionType));
    }

    public String getResponseName() {
        return responseName;
    }

    public void setResponseName(String responseName) {
        this.responseName = responseName;
    }

    public String getEffectiveDate() {
        return effectiveDate;
    }

    public void setEffectiveDate(String effectiveDate) {
        this.effectiveDate = effectiveDate;
    }

    public boolean isActive() {
        return active;
    }

    public void setActive(String active) {
        this.active = Mapper.mapMessageStatus(active);
    }

    public boolean isCustomPublisher() {
        return customPublisher;
    }

    public void setCustomPublisher(boolean customPublisher) {
        this.customPublisher = customPublisher;
    }

    public int getServerNbr() {
        return serverNbr;
    }

    public void setServerNbr(int serverNbr) {
        this.serverNbr = serverNbr;
    }

    @Override
    public String toString() {
        return "Message{" +
                "requestName='" + requestName + '\'' +
                ", responseName='" + responseName + '\'' +
                ", serviceName='" + serviceName + '\'' +
                ", channelName='" + channelName + '\'' +
                ", nodeName='" + nodeName + '\'' +
                ", transactionType='" + transactionType + '\'' +
                ", effectiveDate='" + effectiveDate + '\'' +
                ", active=" + active +
                ", messageType=" + messageType +
                ", serverNbr=" + serverNbr +
                ", customPublisher=" + customPublisher +
                '}';
    }
}
